package cuppics;

import org.junit.Test;

public class Prj1 {

	/**
	 * If we list all the natural numbers below 10 that are multiples of 3 or 5,
	 * we get 3, 5, 6 and 9. The sum of these multiples is 23.
	 * 
	 * Find the sum of all the multiples of 3 or 5 below 1000.
	 */
	@Test
	public void test() {
		
		double num = getSumBelow(1000, 3) + getSumBelow(1000, 5) - getSumBelow(1000, 3 * 5);
		System.out.println("num=" + num);
		
	}
	
	
	public double getSumBelow( int num, int multiple){	
		
		int numOfM = num % multiple == 0 ? (num / multiple - 1) : (num / multiple);
		
		return numOfM * multiple + numOfM * ( numOfM - 1) / 2 * multiple;
	}
	
	
}
